﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.Package;
    using Microsoft.VisualStudio.TextManager.Interop;

namespace Expect.Vs2008.Extensions.LanguageService
{    
    public class Parser
    {
        private ParseRequest _request;

        public ParseRequest Request
        {
            get { return this._request; }
        }

        public AuthoringSink Sink
        {
            get { return this.Request.Sink; }
        }

        public void SetParseRequest(ParseRequest request)
        {
            _request = request;
        }

        public void Parse()
        {
            
        }

        // error reporting
        public void ReportError(TextSpan span, string message, Severity severity)
        {
            Sink.AddError(_request.FileName, message, span, severity);
        }

        #region Error Overloads (Severity)
        public void ReportError(TextSpan location, string message)
        {
            ReportError(location, message, Severity.Error);
        }

        public void ReportFatal(TextSpan location, string message)
        {
            ReportError(location, message, Severity.Fatal);
        }

        public void ReportWarning(TextSpan location, string message)
        {
            ReportError(location, message, Severity.Warning);
        }

        public void ReportHint(TextSpan location, string message)
        {
            ReportError(location, message, Severity.Hint);
        }
        #endregion

        #region TextSpan Conversion
        public TextSpan TextSpan(int startLine, int startIndex, int endIndex)
        {
            return TextSpan(startLine, startIndex, startLine, endIndex);
        }

        public TextSpan TextSpan(int startLine, int startIndex, int endLine, int endIndex)
        {
            TextSpan ts;
            ts.iStartLine = startLine - 1;
            ts.iStartIndex = startIndex;
            ts.iEndLine = endLine - 1;
            ts.iEndIndex = endIndex;
            return ts;
        }
        #endregion
    }
}
